<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
/* Start of file gass.php */
/* Location: ./billing-ar/models/gas.php */
class Gas extends CI_Model {
    
	function __construct(){
        parent::__construct(); /** Call the Model constructor */
    }
    
    function getDailyEvc($month,$year,$customer='',$date='',$dateOf=''){
        if($date!=''):
            $this->db->select('DISTINCT Date,DAYNAME(Date) as day_name',FALSE);
        else:
            $this->db->select('*',FALSE);
        endif;    
        $this->db->where('Bulan',$month);
        $this->db->where('Tahun',$year);
        
        if($dateOf!=''):
            $this->db->where('Date',$dateOf);
        endif;    
            
        if($customer)
            $this->db->where('CustID',$customer);
            
        $this->db->order_by('Date','ASC');
        $Q = $this->db->get('daily_evc');
        if($dateOf!=''):
            $data = $Q->row_array();
        else:
            $data = $Q->result_array();
        endif;
        return $data;    
    }
    
    function AverageGas($average,$month,$year,$cust){
        /** select avg (FlowRate) as average  from daily_evc where Bulan='$bln' and Tahun='$thn' and CustID='$row_cust2[CustID]'**/
        $this->db->select_avg($average);
        $this->db->where('Bulan',$month);
        $this->db->where('Tahun',$year);
        $this->db->where('CustID',$cust);
        $Q=$this->db->get('daily_evc');
        return $Q->row_array();
    }
    
    function getSUMDailyEvc($sum,$month,$year,$cust){
        /** select avg (FlowRate) as average  from daily_evc where Bulan='$bln' and Tahun='$thn' and CustID='$row_cust2[CustID]'**/
        $this->db->select_sum($sum);
        $this->db->where('Bulan',$month);
        $this->db->where('Tahun',$year);
        $this->db->where('CustID',$cust);
        $Q=$this->db->get('daily_evc');
        return $Q->row_array();
    }
    
    function getDailyTpc($month,$year,$customer){
        $this->db->select('*');
        $this->db->where('Bulan',$month);
        $this->db->where('Tahun',$year);
        $this->db->where('CustID',$customer);
        $this->db->order_by('Date','ASC');
        $Q = $this->db->get('daily_turbin');
        return $Q->result_array();     
    }    
 
    function getDailyCutOff($month,$year,$customer){
        /** $sql_head="select * from daily_cutoff where CustID='$customer' and Tahun='$thn' and Bulan='$bln'"; **/
        $this->db->select('*');
        $this->db->join('customer','customer.CustID=daily_cutoff.CustID','INNER');
        $this->db->where('Bulan',$month);
        $this->db->where('Tahun',$year);
        $this->db->where('daily_cutoff.CustID',$customer);
        $Q = $this->db->get('daily_cutoff',1);
        return $Q->row_array();
    }
    
    function getPdfEVC($month,$year,$cust){
        $head = $this->getDailyCutOff($month,$year,$cust);
        $evc  = $this->getDailyEvc($month,$year,$cust);/** Get Gas Daily EVC **/
            
        $pdf = tcpdf();
        $pdf->setPrintHeader(false);
        $pdf->setPrintFooter(false);
        $k=0;
        $pdf->AddPage(); 
        
        /** initialization of x & y axis **/
        $x_axis_initial = 7;
        $y_axis_initial = 7;
        $x_axis = $x_axis_initial;
        $y_axis = $y_axis_initial;
        
        $pdf->SetFont('helvetica', '', 12);
        $pdf->SetFillColor(255, 255, 255);
        $pdf->SetTextColor(0, 0, 0);
        $pdf->SetDrawColor(0, 0, 0);
        $pdf->SetLineWidth(0.3);
        
        $y_axis0=$y_axis+7; 
        $y_axis=$y_axis;
        
        $pdf->SetY($y_axis0);
        $pdf->SetX($x_axis_initial); 	
        $pdf->SetY($y_axis);
        $pdf->SetX($x_axis_initial+4);
        $pdf->Cell(190, 7, 'Daily Record EVC', 0, 0, 'C', 1);
        
        $y_axis=$y_axis+7; 
        $pdf->SetY($y_axis); $pdf->SetX($x_axis_initial+4);
        $pdf->Cell(190, 7, 'PT. Bayu Buana Gemilang', 0, 0, 'C', 1);
        
        $y_axis=$y_axis+11;
 
        $pdf->SetFont('helvetica', '', 8);
        $pdf->SetY($y_axis);
        $pdf->SetX($x_axis_initial); 	
        $pdf->MultiCell(30, 5, 'Customer Name', 0, 'L', 0, 0, '', '', true);
        $pdf->MultiCell(110, 5, ': '.$head['Perusahaan'], 0, 'L', 0, 0, '', '', true);
        
        $pdf->MultiCell(10, 5, 'Area', 0, 'L', 0, 0, '', '', true);
        $pdf->MultiCell(50, 5, ': '.$head['CustomerGroup'], 0, 'L', 0, 0, '', '', true); 
        
        $y_axis=$y_axis+5;
        $pdf->SetY($y_axis);
        $pdf->SetX($x_axis_initial); 	
        $pdf->MultiCell(30, 5, 'Identity od MR/S', 0, 'L', 0, 0, '', '', true);
        $pdf->MultiCell(110, 5, ': '.$head['MRS'], 0, 'L', 0, 0, '', '', true);
        
        $pdf->MultiCell(10, 5, 'Year', 0, 'L', 0, 0, '', '', true);
        $pdf->MultiCell(50, 5, ': '.$year, 0, 'L', 0, 0, '', '', true);
        
        $y_axis=$y_axis+5;
        $pdf->SetY($y_axis);
        $pdf->SetX($x_axis_initial); 	
        $pdf->MultiCell(30, 5, 'Periode', 0, 'L', 0, 0, '', '', true);
        $pdf->MultiCell(110, 5, ': '.$month, 0, 'L', 0, 0, '', '', true);
        
        $pdf->SetFillColor(205, 201, 201);
        $pdf->SetFont('helvetica', 'B', 9); 
       	
        $y_axis=$y_axis+7;
        $pdf->SetY($y_axis);
        $pdf->SetX($x_axis_initial); 	
        $pdf->Cell(7, 6, 'No', 1, 1, 'C', 1, '', 0, false, 'T', 'C');
        
       	$x_axis=$x_axis+7;
        $pdf->SetY($y_axis);
        $pdf->SetX($x_axis); 	
        $pdf->Cell(20, 6, 'Date', 1, 1, 'C', 1, '', 0, false, 'T', 'C');
        
       	$x_axis=$x_axis+20;
        $pdf->SetY($y_axis);
        $pdf->SetX($x_axis); 	
        $pdf->Cell(12, 6, 'Time', 1, 1, 'C', 1, '', 0, false, 'T', 'C');
        
       	$x_axis=$x_axis+12;
        $pdf->SetY($y_axis);
        $pdf->SetX($x_axis); 	
        $pdf->Cell(16, 6, 'Pressure', 1, 1, 'C', 1, '', 0, false, 'T', 'C');
        
       	$x_axis=$x_axis+16;
        $pdf->SetY($y_axis);
        $pdf->SetX($x_axis); 	
        $pdf->Cell(22, 6, 'Temperature', 1, 1, 'C', 1, '', 0, false, 'T', 'C');
       	
        $x_axis=$x_axis+22;
        $pdf->SetY($y_axis);
        $pdf->SetX($x_axis); 	
        $pdf->Cell(39, 6, 'Corrected Vol. Index', 1, 1, 'C', 1, '', 0, false, 'T', 'C');
        
       	$x_axis=$x_axis+39;
        $pdf->SetY($y_axis);
        $pdf->SetX($x_axis); 	
        $pdf->Cell(36, 6, 'Corrected Volume', 1, 1, 'C', 1, '', 0, false, 'T', 'C');
        
       	$x_axis=$x_axis+36;
        $pdf->SetY($y_axis);
        $pdf->SetX($x_axis); 	
        $pdf->Cell(22, 6, 'Cummulative', 1, 1, 'C', 1, '', 0, false, 'T', 'C');
        
       	$x_axis=$x_axis+22;
        $pdf->SetY($y_axis);
        $pdf->SetX($x_axis); 	
        $pdf->Cell(20, 6, 'Flow Rate', 1, 1, 'C', 1, '', 0, false, 'T', 'C');
        
        $pdf->SetFillColor(255, 255, 255);

        $y_axis=$y_axis+6;
        $pdf->SetY($y_axis);
        $pdf->SetX($x_axis_initial); 	
        $pdf->MultiCell(7, 4, '0', 1, 'C', 0, 0, '', '', true);
        $pdf->MultiCell(20, 4, indonesian_date($head['Date']), 1, 'C', 0, 0, '', '', true); 
        $pdf->MultiCell(12, 4, '', 1, 'C', 0, 0, '', '', true); 
        $pdf->MultiCell(16, 4, '', 1, 'C', 0, 0, '', '', true); 
        $pdf->MultiCell(22, 4, '', 1, 'C', 0, 0, '', '', true); 
        $pdf->MultiCell(39, 4, number_format($head['CorrrectedVolumeIndex'],0,".",","), 1, 'R', 0, 0, '', '', true); 
        $pdf->MultiCell(36, 4, '', 1, 'C', 0, 0, '', '', true); 
        $pdf->MultiCell(22, 4, '', 1, 'C', 0, 0, '', '', true); 
        $pdf->MultiCell(20, 4, '', 1, 'C', 0, 0, '', '', true); 
        
        $pdf->SetFont('helvetica', '', 8);
        $y_axis=$y_axis+4;
        $pdf->SetY($y_axis);
        $pdf->SetX($x_axis_initial); 	
        $pdf->MultiCell(7, 4, '', 1, 'C', 0, 0, '', '', true);
        $pdf->MultiCell(20, 4, '', 1, 'C', 0, 0, '', '', true); 
        $pdf->MultiCell(12, 4, '', 1, 'C', 0, 0, '', '', true); 
        $pdf->MultiCell(16, 4, '', 1, 'C', 0, 0, '', '', true); 
        $pdf->MultiCell(22, 4, '', 1, 'C', 0, 0, '', '', true); 
        $pdf->MultiCell(39, 4, '', 1, 'C', 0, 0, '', '', true); 
        $pdf->MultiCell(36, 4, '', 1, 'C', 0, 0, '', '', true); 
        $pdf->MultiCell(22, 4, '', 1, 'C', 0, 0, '', '', true); 
        $pdf->MultiCell(20, 4, '', 1, 'C', 0, 0, '', '', true); 
        
        $i = 1;
        $total = 0;
        foreach($evc as $row):
            $y_axis=$y_axis+4;
        	$pdf->SetY($y_axis); $pdf->SetX($x_axis_initial); 	
        	$pdf->MultiCell(7, 4, $i, 1, 'C', 0, 0, '', '', true);
        	$pdf->MultiCell(20, 4, indonesian_date($row['Date']), 1, 'C', 0, 0, '', '', true); 
        	$pdf->MultiCell(12, 4, substr($row['Time'],0,5), 1, 'C', 0, 0, '', '', true); 
        	$pdf->MultiCell(16, 4, decimal($row['Pressure'],2), 1, 'R', 0, 0, '', '', true); 
        	$pdf->MultiCell(22, 4, decimal($row['Temperature'],2), 1, 'R', 0, 0, '', '', true); 
        	$pdf->MultiCell(39, 4, decimal($row['CorrectedVolumeIndex'],2), 1, 'R', 0, 0, '', '', true); 
        	$pdf->MultiCell(36, 4, decimal($row['CorrectedVolume'],2), 1, 'R', 0, 0, '', '', true); 
        	$pdf->MultiCell(22, 4, decimal($row['Cummulative'],2), 1, 'R', 0, 0, '', '', true); 
        	$pdf->MultiCell(20, 4, decimal($row['FlowRate'],1,".",","), 1, 'R', 0, 0, '', '', true);		
            $i++;
            $total=$total + $row['CorrectedVolume'];
        endforeach;
        
        $pdf->SetFillColor(205, 201, 201);  
        $pdf->SetFont('helvetica', 'B', 9); 
        $y_axis=$y_axis+4;
        
        $pdf->SetY($y_axis);
        $pdf->SetX($x_axis_initial); 	
        $pdf->Cell(77, 5, 'TOTAL', 1, 1, 'C', 1, '', 0, false, 'T', 'C');
        
        $x_axis=$x_axis_initial+77;
        $pdf->SetY($y_axis);
        $pdf->SetX($x_axis); 	
        $pdf->Cell(39, 5, decimal($total,0), 1, 1, 'R', 1, '', 0, false, 'T', 'C');
        
        $x_axis=$x_axis+39;
        $pdf->SetY($y_axis);
        $pdf->SetX($x_axis); 	
        $pdf->Cell(78, 5, '', 1, 1, 'R', 1, '', 0, false, 'T', 'C');
        
        $pdf->SetFont('helvetica', '', 9); 
        $pdf->SetFillColor(255, 255, 255);
        
        $y_axis=$y_axis+8;
        $pdf->SetY($y_axis);
        $pdf->SetX($x_axis_initial+140); 	
        $pdf->MultiCell(70, 4, 'Cibitung, '.$month.' '.$year, 0, 'C', 0, 0, '', '', true); 
          
        $y_axis=$y_axis+4;
        $pdf->SetY($y_axis);
        $pdf->SetX($x_axis_initial+10); 	
        $pdf->MultiCell(40, 4, $head['Perusahaan'], 0, 'C', 0, 0, '', '', true); 
        $pdf->MultiCell(90, 4, '', 0, 'C', 0, 0, '', '', true); 
        $pdf->MultiCell(70, 4, 'PT. Bayu Buana Gemilang', 0, 'C', 0, 0, '', '', true); 
         
        $y_axis=$y_axis+24;
        $pdf->SetY($y_axis);
        $pdf->SetX($x_axis_initial+10); 	
        $pdf->MultiCell(40, 4, '('.str_repeat("_",20).')', 0, 'C', 0, 0, '', '', true); 
        $pdf->MultiCell(90, 4, '', 0, 'C', 0, 0, '', '', true); 
        $pdf->MultiCell(70, 4, 'Operation Spv', 0, 'C', 0, 0, '', '', true); 
                                
        return $pdf->Output("EVC.pdf","I"); 
    } 
    
    function getPdfTPC($month,$year,$cust){
        $head = $this->getDailyCutOff($month,$year,$cust);
        $tpc  = $this->getDailyTpc($month,$year,$cust);/** Get Gas Daily EVC **/
            
        $pdf = tcpdf();
        $pdf->setPrintHeader(false);
        $pdf->setPrintFooter(false);
        $k=0;
        $pdf->AddPage(); 
        
        /** initialization of x & y axis **/
        $x_axis_initial = 7;
        $y_axis_initial = 7;
        $x_axis = $x_axis_initial;
        $y_axis = $y_axis_initial;
        
        $pdf->SetFont('helvetica', '', 12);
        $pdf->SetFillColor(255, 255, 255);
        $pdf->SetTextColor(0, 0, 0);
        $pdf->SetDrawColor(0, 0, 0);
        $pdf->SetLineWidth(0.3);
        
        $y_axis0=$y_axis+7; 
        $y_axis=$y_axis;
        
        $pdf->SetY($y_axis0);
        $pdf->SetX($x_axis_initial); 	
        $pdf->SetY($y_axis);
        $pdf->SetX($x_axis_initial+4);
        $pdf->Cell(190, 7, 'Daily Record Turbin', 0, 0, 'C', 1);
        
        $y_axis=$y_axis+7; 
        $pdf->SetY($y_axis); $pdf->SetX($x_axis_initial+4);
        $pdf->Cell(190, 7, 'PT. Bayu Buana Gemilang', 0, 0, 'C', 1);
        
        $y_axis=$y_axis+11;
 
        $pdf->SetFont('helvetica', '', 8);
        $pdf->SetY($y_axis);
        $pdf->SetX($x_axis_initial); 	
        $pdf->MultiCell(30, 5, 'Customer Name', 0, 'L', 0, 0, '', '', true);
        $pdf->MultiCell(110, 5, ': '.$head['Perusahaan'], 0, 'L', 0, 0, '', '', true);
        
        $pdf->MultiCell(10, 5, 'Area', 0, 'L', 0, 0, '', '', true);
        $pdf->MultiCell(50, 5, ': '.$head['CustomerGroup'], 0, 'L', 0, 0, '', '', true); 
        
        $y_axis=$y_axis+5;
        $pdf->SetY($y_axis);
        $pdf->SetX($x_axis_initial); 	
        $pdf->MultiCell(30, 5, 'Identity od MR/S', 0, 'L', 0, 0, '', '', true);
        $pdf->MultiCell(110, 5, ': '.$head['MRS'], 0, 'L', 0, 0, '', '', true);
        
        $pdf->MultiCell(10, 5, 'Year', 0, 'L', 0, 0, '', '', true);
        $pdf->MultiCell(50, 5, ': '.$year, 0, 'L', 0, 0, '', '', true);
        
        $y_axis=$y_axis+5;
        $pdf->SetY($y_axis);
        $pdf->SetX($x_axis_initial); 	
        $pdf->MultiCell(30, 5, 'Periode', 0, 'L', 0, 0, '', '', true);
        $pdf->MultiCell(110, 5, ': '.$month, 0, 'L', 0, 0, '', '', true);
        
        $pdf->SetFillColor(205, 201, 201);
        $pdf->SetFont('helvetica', 'B', 9); 
       	
        $y_axis=$y_axis+7;
        $pdf->SetY($y_axis);
        $pdf->SetX($x_axis_initial); 	
        $pdf->Cell(7, 6, 'No', 1, 1, 'C', 1, '', 0, false, 'T', 'C');
        
       	$x_axis=$x_axis+7;
        $pdf->SetY($y_axis);
        $pdf->SetX($x_axis); 	
        $pdf->Cell(20, 6, 'Date', 1, 1, 'C', 1, '', 0, false, 'T', 'C');
        
       	$x_axis=$x_axis+20;
        $pdf->SetY($y_axis);
        $pdf->SetX($x_axis); 	
        $pdf->Cell(12, 6, 'Time', 1, 1, 'C', 1, '', 0, false, 'T', 'C');
        
       	$x_axis=$x_axis+12;
        $pdf->SetY($y_axis);
        $pdf->SetX($x_axis); 	
        $pdf->Cell(16, 6, 'Pressure', 1, 1, 'C', 1, '', 0, false, 'T', 'C');
        
       	$x_axis=$x_axis+16;
        $pdf->SetY($y_axis);
        $pdf->SetX($x_axis); 	
        $pdf->Cell(22, 6, 'Temperature', 1, 1, 'C', 1, '', 0, false, 'T', 'C');
       	
        $x_axis=$x_axis+22;
        $pdf->SetY($y_axis);
        $pdf->SetX($x_axis); 	
        $pdf->Cell(39, 6, 'Uncorrected Vol. Index', 1, 1, 'C', 1, '', 0, false, 'T', 'C');
        
       	$x_axis=$x_axis+39;
        $pdf->SetY($y_axis);
        $pdf->SetX($x_axis); 	
        $pdf->Cell(36, 6, 'Uncorrected Volume', 1, 1, 'C', 1, '', 0, false, 'T', 'C');
        
       	$x_axis=$x_axis+36;
        $pdf->SetY($y_axis);
        $pdf->SetX($x_axis); 	
        $pdf->Cell(22, 6, 'Cummulative', 1, 1, 'C', 1, '', 0, false, 'T', 'C');
        
       	$x_axis=$x_axis+22;
        $pdf->SetY($y_axis);
        $pdf->SetX($x_axis); 	
        $pdf->Cell(20, 6, 'Flow Rate', 1, 1, 'C', 1, '', 0, false, 'T', 'C');
        
        $pdf->SetFillColor(255, 255, 255);

        $y_axis=$y_axis+6;
        $pdf->SetY($y_axis);
        $pdf->SetX($x_axis_initial); 	
        $pdf->MultiCell(7, 4, '0', 1, 'C', 0, 0, '', '', true);
        $pdf->MultiCell(20, 4, indonesian_date($head['Date']), 1, 'C', 0, 0, '', '', true); 
        $pdf->MultiCell(12, 4, '', 1, 'C', 0, 0, '', '', true); 
        $pdf->MultiCell(16, 4, '', 1, 'C', 0, 0, '', '', true); 
        $pdf->MultiCell(22, 4, '', 1, 'C', 0, 0, '', '', true); 
        $pdf->MultiCell(39, 4, number_format($head['UncorrectedVolumeIndex'],0,".",","), 1, 'R', 0, 0, '', '', true); 
        $pdf->MultiCell(36, 4, '', 1, 'C', 0, 0, '', '', true); 
        $pdf->MultiCell(22, 4, '', 1, 'C', 0, 0, '', '', true); 
        $pdf->MultiCell(20, 4, '', 1, 'C', 0, 0, '', '', true); 
        
        $pdf->SetFont('helvetica', '', 8);
        $y_axis=$y_axis+4;
        $pdf->SetY($y_axis);
        $pdf->SetX($x_axis_initial); 	
        $pdf->MultiCell(7, 4, '', 1, 'C', 0, 0, '', '', true);
        $pdf->MultiCell(20, 4, '', 1, 'C', 0, 0, '', '', true); 
        $pdf->MultiCell(12, 4, '', 1, 'C', 0, 0, '', '', true); 
        $pdf->MultiCell(16, 4, '', 1, 'C', 0, 0, '', '', true); 
        $pdf->MultiCell(22, 4, '', 1, 'C', 0, 0, '', '', true); 
        $pdf->MultiCell(39, 4, '', 1, 'C', 0, 0, '', '', true); 
        $pdf->MultiCell(36, 4, '', 1, 'C', 0, 0, '', '', true); 
        $pdf->MultiCell(22, 4, '', 1, 'C', 0, 0, '', '', true); 
        $pdf->MultiCell(20, 4, '', 1, 'C', 0, 0, '', '', true); 
        
        $i = 1;
        $total = 0;
        foreach($tpc as $row):
            $y_axis=$y_axis+4;
        	$pdf->SetY($y_axis); $pdf->SetX($x_axis_initial); 	
        	$pdf->MultiCell(7, 4, $i, 1, 'C', 0, 0, '', '', true);
        	$pdf->MultiCell(20, 4, indonesian_date($row['Date']), 1, 'C', 0, 0, '', '', true); 
        	$pdf->MultiCell(12, 4, substr($row['Time'],0,5), 1, 'C', 0, 0, '', '', true); 
        	$pdf->MultiCell(16, 4, '0.00', 1, 'R', 0, 0, '', '', true); 
        	$pdf->MultiCell(22, 4, decimal($row['Temperature'],2), 1, 'R', 0, 0, '', '', true); 
        	$pdf->MultiCell(39, 4, decimal($row['UncorrectedVolumeIndex'],2), 1, 'R', 0, 0, '', '', true); 
        	$pdf->MultiCell(36, 4, decimal($row['UncorrectedVolume'],2), 1, 'R', 0, 0, '', '', true); 
        	$pdf->MultiCell(22, 4, decimal($row['Cummulative'],2), 1, 'R', 0, 0, '', '', true); 
        	$pdf->MultiCell(20, 4, decimal($row['FlowRate'],1,".",","), 1, 'R', 0, 0, '', '', true);		
            $i++;
            $total=$total + $row['UncorrectedVolume'];
        endforeach;
        
        $pdf->SetFillColor(205, 201, 201);  
        $pdf->SetFont('helvetica', 'B', 9); 
        $y_axis=$y_axis+4;
        
        $pdf->SetY($y_axis);
        $pdf->SetX($x_axis_initial); 	
        $pdf->Cell(77, 5, 'TOTAL', 1, 1, 'C', 1, '', 0, false, 'T', 'C');
        
        $x_axis=$x_axis_initial+77;
        $pdf->SetY($y_axis);
        $pdf->SetX($x_axis); 	
        $pdf->Cell(39, 5, decimal($total,0), 1, 1, 'R', 1, '', 0, false, 'T', 'C');
        
        $x_axis=$x_axis+39;
        $pdf->SetY($y_axis);
        $pdf->SetX($x_axis); 	
        $pdf->Cell(78, 5, '', 1, 1, 'R', 1, '', 0, false, 'T', 'C');
        
        $pdf->SetFont('helvetica', '', 9); 
        $pdf->SetFillColor(255, 255, 255);
        
        $y_axis=$y_axis+8;
        $pdf->SetY($y_axis);
        $pdf->SetX($x_axis_initial+140); 	
        $pdf->MultiCell(70, 4, 'Cibitung, '.$month.' '.$year, 0, 'C', 0, 0, '', '', true); 
          
        $y_axis=$y_axis+4;
        $pdf->SetY($y_axis);
        $pdf->SetX($x_axis_initial+10); 	
        $pdf->MultiCell(40, 4, $head['Perusahaan'], 0, 'C', 0, 0, '', '', true); 
        $pdf->MultiCell(90, 4, '', 0, 'C', 0, 0, '', '', true); 
        $pdf->MultiCell(70, 4, 'PT. Bayu Buana Gemilang', 0, 'C', 0, 0, '', '', true); 
         
        $y_axis=$y_axis+24;
        $pdf->SetY($y_axis);
        $pdf->SetX($x_axis_initial+10); 	
        $pdf->MultiCell(40, 4, '('.str_repeat("_",20).')', 0, 'C', 0, 0, '', '', true); 
        $pdf->MultiCell(90, 4, '', 0, 'C', 0, 0, '', '', true); 
        $pdf->MultiCell(70, 4, 'Operation Spv', 0, 'C', 0, 0, '', '', true); 
                                
        return $pdf->Output("TPC.pdf","I"); 
    }
    
    function getPdfGasConsumption($month,$year,$cust){
        $invoice = $this->invoices->getItemInvoice($cust,$month,$year);
        if($invoice)
             $invoice = $invoice['InvoiceID'];
        else $invoice = '-';       
        $pjbg    = $this->invoices->getPjbg($invoice);
        if($pjbg)
             $pjbg = $pjbg['pjbg_id'];
        else $pjbg = '-';    
        $ghv     = $this->invoices->getGhv($invoice);
        $metering= $this->invoices->getMetering($cust,$month,$year,$pjbg);     
        $customer= $this->customers->getCustomer($cust); 
        $line    = $this->invoices->getMeteringLine('USD',$pjbg,$invoice);
        $line2   = $this->invoices->getMeteringLine('IDR',$pjbg,$invoice);
            
        $pdf = tcpdf();
        $pdf->setPrintHeader(false);
        $pdf->setPrintFooter(false);
        $k=0;
        $pdf->AddPage();
        
        /** initialization of x & y axis **/
        $x_axis_initial = 7;
        $y_axis_initial = 7;
        $x_axis = $x_axis_initial;
        $y_axis = $y_axis_initial; 
         
        $pdf->SetFont('helvetica', 'B', 11);
        $pdf->SetFillColor(255, 255, 255);
        $pdf->SetTextColor(0, 0, 0);
        $pdf->SetDrawColor(0, 0, 0);
        $pdf->SetLineWidth(0.3); 
    
        $y_axis0=$y_axis+7; 
        $y_axis=$y_axis;
        $pdf->SetY($y_axis0);
        $pdf->SetX($x_axis_initial); 	
        $pdf->SetY($y_axis);
        $pdf->SetX($x_axis_initial+4);
        $pdf->Cell(190, 7, 'MONTHLY GAS CONSUMPTION', 0, 0, 'C', 1);
        
        $y_axis=$y_axis+12;
        $pdf->SetFont('helvetica', '', 7);
        
        $pdf->SetY($y_axis);
        $pdf->SetX($x_axis_initial+63); 
        $pdf->MultiCell(70, 5, ' Month', 1, 'L', 0, 0, '', '', true, 0, false, true, 5, 'M');
        
        $pdf->SetY($y_axis);
        $pdf->SetX($x_axis_initial+95);
        $pdf->MultiCell(5, 5, ': ', 0, 'L', 0, 0, '', '', true, 0, false, true, 5, 'M');
        
        $pdf->SetY($y_axis);
        $pdf->SetX($x_axis_initial+100);
        $pdf->SetFont('helvetica', 'B', 7);
        $pdf->MultiCell(28, 5, month_name($month), 0, 'C', 0, 0, '', '', true, 0, false, true, 5, 'M');
        
        $pdf->SetFont('helvetica', '', 7);
        
        $y_axis=$y_axis+5;
        $pdf->SetY($y_axis);
        $pdf->SetX($x_axis_initial+63);
        $pdf->MultiCell(70, 5, ' Year', 1, 'L', 0, 0, '', '', true, 0, false, true, 5, 'M');
        
        $pdf->SetY($y_axis);
        $pdf->SetX($x_axis_initial+95);
        $pdf->MultiCell(5, 5, ': ', 0, 'L', 0, 0, '', '', true, 0, false, true, 5, 'M');
        
        $pdf->SetY($y_axis);
        $pdf->SetX($x_axis_initial+100);
        $pdf->SetFont('helvetica', 'B', 7);
        $pdf->MultiCell(28, 5, $year, 0, 'C', 0, 0, '', '', true, 0, false, true, 5, 'M');
        
        $y_axis=$y_axis+5;
        $pdf->Line($x_axis_initial, $y_axis+5, 205, $y_axis+5);
        
        $pdf->SetFont('helvetica', 'B', 7);
        
        $y_axis=$y_axis+3;
        $pdf->SetY($y_axis);
        $pdf->SetX($x_axis_initial); 	
        $pdf->Text($x_axis_initial, $y_axis+3, 'CONTRACT DATA');
        
        $y_axis=$y_axis+10;
        $pdf->SetFont('helvetica', '', 6);
        $pdf->SetY($y_axis);
        $pdf->SetX($x_axis_initial); 	
        $pdf->MultiCell(98, 4, 'PJBG No.', 1, 'L', 0, 0, '', '', true, 0, false, true, 4, 'M');
        
        $pdf->SetY($y_axis); $pdf->SetX($x_axis_initial+25);
        $pdf->MultiCell(73, 4, ': '.$pjbg['Nomor'], 0, 'L', 0, 0, '', '', true, 0, false, true, 4, 'M');
        
        $pdf->SetY($y_axis);
        $pdf->SetX($x_axis_initial+100);
        $pdf->MultiCell(98, 4, 'Minimum Contract Volume', 1, 'L', 0, 0, '', '', true, 0, false, true, 4, 'M');
        
        $pdf->SetY($y_axis);
        $pdf->SetX($x_axis_initial+145);
        $pdf->MultiCell(98, 4, ': '.number_format($pjbg['MinContract'],0,".",","), 0, 'L', 0, 0, '', '', true, 0, false, true, 4, 'M');
        
        $pdf->SetY($y_axis); $pdf->SetX($x_axis_initial+175); 
        $pdf->MultiCell(28, 4, 'Sm3/month ', 0, 'L', 0, 0, '', '', true, 0, false, true, 4, 'M');
        
        $y_axis=$y_axis+4;
        $pdf->SetY($y_axis);
        $pdf->SetX($x_axis_initial); 	
        $pdf->MultiCell(98, 4, 'Letter No.', 1, 'L', 0, 0, '', '', true, 0, false, true, 4, 'M');
        
        $pdf->SetY($y_axis);
        $pdf->SetX($x_axis_initial+25);
        $pdf->MultiCell(73, 4, ': '.$pjbg['Ref'], 0, 'L', 0, 0, '', '', true, 0, false, true, 4, 'M');
        
        $pdf->SetY($y_axis);
        $pdf->SetX($x_axis_initial+100);
        $pdf->MultiCell(98, 4, 'Maximum Contract Volume', 1, 'L', 0, 0, '', '', true, 0, false, true, 4, 'M');
        
        $pdf->SetY($y_axis);
        $pdf->SetX($x_axis_initial+145);
        $pdf->MultiCell(98, 4, ': '.number_format($pjbg['MaxContract'],0,".",","), 0, 'L', 0, 0, '', '', true, 0, false, true, 4, 'M');
        
        $pdf->SetY($y_axis);
        $pdf->SetX($x_axis_initial+175); 
        $pdf->MultiCell(28, 4, 'Sm3/month ', 0, 'L', 0, 0, '', '', true, 0, false, true, 4, 'M');
        
        $y_axis=$y_axis+4;
        
        $pdf->SetY($y_axis);
        $pdf->SetX($x_axis_initial); 	
        $pdf->MultiCell(98, 4, 'Customer ID No.', 1, 'L', 0, 0, '', '', true, 0, false, true, 4, 'M');
        
        $pdf->SetY($y_axis);
        $pdf->SetX($x_axis_initial+25);
        $pdf->MultiCell(73, 4, ': '.$customer['CustID'], 0, 'L', 0, 0, '', '', true, 0, false, true, 4, 'M');
        
        $pdf->SetY($y_axis);
        $pdf->SetX($x_axis_initial+100);
        $pdf->MultiCell(98, 4, 'Maximum Excess Volume', 1, 'L', 0, 0, '', '', true, 0, false, true, 4, 'M');
        
        $pdf->SetY($y_axis);
        $pdf->SetX($x_axis_initial+145);
        $excess0= ($pjbg['Excess']/100) * $pjbg['MaxContract'];
        $excess = $pjbg['MaxContract'] + $excess0;
        $pdf->MultiCell(98, 4, ': '.number_format($excess,0,".",","), 0, 'L', 0, 0, '', '', true, 0, false, true, 4, 'M');
        
        $pdf->SetY($y_axis);
        $pdf->SetX($x_axis_initial+175); 
        $pdf->MultiCell(28, 4, 'Sm3/month ', 0, 'L', 0, 0, '', '', true, 0, false, true, 4, 'M');
        
        $y_axis=$y_axis+4;
        $pdf->SetY($y_axis);
        $pdf->SetX($x_axis_initial); 	
        $pdf->MultiCell(98, 4, 'Company Name', 1, 'L', 0, 0, '', '', true, 0, false, true, 4, 'M');
        
        $pdf->SetY($y_axis);
        $pdf->SetX($x_axis_initial+25);
        $pdf->MultiCell(73, 4, ': '.$customer['Perusahaan'], 0, 'L', 0, 0, '', '', true, 0, false, true, 4, 'M');
    
        $y_axis=$pdf->getY();
        $y_axis=$y_axis+8;
        $pdf->SetFont('helvetica', 'B', 7);
        $pdf->SetY($y_axis);
        $pdf->SetX($x_axis_initial); 	
        $pdf->Line($x_axis_initial, $y_axis+5, 205, $y_axis+5);
        
        $pdf->SetFont('helvetica', 'B', 7);
        $y_axis=$y_axis+3;
        $pdf->SetY($y_axis);
        $pdf->SetX($x_axis_initial); 	
        $pdf->Text($x_axis_initial, $y_axis+3, 'LABORAT DATA');
        
        $pdf->SetFont('helvetica', '', 6);
        $y_axis=$y_axis+10; $y_axis0=$y_axis;
        
        $week=1;
        $total = 0;
        $tot_ghv = count($ghv); 
        foreach($ghv as $row_ghv):
            $pdf->SetY($y_axis);
            $pdf->SetX($x_axis_initial); 	
        	$pdf->MultiCell(98, 4, 'Week '.$week.'  : ', 1, 'L', 0, 0, '', '', true, 0, false, true, 4, 'M');
            
        	$pdf->SetY($y_axis);
            $pdf->SetX($x_axis_initial+18);
        	$pdf->MultiCell(40, 4, $row_ghv['Keterangan'], 0, 'L', 0, 0, '', '', true, 0, false, true, 4, 'M');
        	
            $pdf->SetY($y_axis);
            $pdf->SetX($x_axis_initial+58);
        	$pdf->MultiCell(22, 4, number_format($row_ghv['GHV'],"4",".",","), 0, 'L', 0, 0, '', '', true, 0, false, true, 4, 'M');
        	
            $pdf->SetY($y_axis);
            $pdf->SetX($x_axis_initial+80);
        	$pdf->MultiCell(15, 4, 'Btu/Scf ', 0, 'L', 0, 0, '', '', true, 0, false, true, 4, 'M');	
        	$y_axis=$y_axis+4;
            
        	$week++;
            $total = $total + $row_ghv['GHV'];
        endforeach;
        
        $avg = $total/($week-1);
        
        if($tot_ghv<4):
        	for($g=$tot_ghv;$g<4;$g++):
        		$pdf->SetY($y_axis);
                $pdf->SetX($x_axis_initial); 	
        		$pdf->MultiCell(98, 4, ' ', 1, 'L', 0, 0, '', '', true, 0, false, true, 4, 'M');
                
        		$pdf->SetY($y_axis);
                $pdf->SetX($x_axis_initial+18);
        		$pdf->MultiCell(40, 4, ' ', 0, 'L', 0, 0, '', '', true, 0, false, true, 4, 'M');
                
        		$pdf->SetY($y_axis);
                $pdf->SetX($x_axis_initial+58);
        		$pdf->MultiCell(22, 4, ' ', 0, 'L', 0, 0, '', '', true, 0, false, true, 4, 'M');
                
        		$pdf->SetY($y_axis);
                $pdf->SetX($x_axis_initial+80);
        		$pdf->MultiCell(15, 4, ' ', 0, 'L', 0, 0, '', '', true, 0, false, true, 4, 'M');	
        		$y_axis=$y_axis+4;
        	endfor;
        endif;
        
        
        if($avg!=""):
        	$average = $avg * 35.31466672;
        	$mmbtu =1000000 / $average;
        	
            $pdf->SetFont('helvetica', 'B', 6);
        	$pdf->SetY($y_axis);
            $pdf->SetX($x_axis_initial); 	
        	$pdf->Line($x_axis_initial, $y_axis+1, 105, $y_axis+1);
        	$pdf->MultiCell(98, 6, 'Average  : ', 1, 'L', 0, 0, '', '', true, 0, false, true, 5, 'B');
            
        	$pdf->SetY($y_axis);
            $pdf->SetX($x_axis_initial+18);
        	$pdf->MultiCell(40, 6, '', 0, 'L', 0, 0, '', '', true, 0, false, true, 5, 'B');
            
        	$pdf->SetY($y_axis);
            $pdf->SetX($x_axis_initial+58);
        	$pdf->MultiCell(22, 6, number_format($avg,"4",".",","), 0, 'L', 0, 0, '', '', true, 0, false, true, 5, 'B');
        	
            $pdf->SetY($y_axis);
            $pdf->SetX($x_axis_initial+80);
        	$pdf->MultiCell(15, 6, 'Btu/Scf ', 0, 'L', 0, 0, '', '', true, 0, false, true, 5, 'B');	
        	$y_axis=$y_axis+6;
        endif;
        
        $pdf->SetLineStyle(array('width' => 0.3, 'cap' => 'butt', 'join' => 'miter', 'dash' => 0, 'color' => array(0, 0, 0)));
        $pdf->SetY($y_axis0);
        $pdf->SetX($x_axis_initial+100);
        $pdf->MultiCell(98, 26,'Conversion', 1, 'L', 0, 0, '', '', true);
        
        $pdf->SetFont('helvetica', '', 6);  	
        $y_axis0=$y_axis0+6;
        $pdf->SetY($y_axis0);
        $pdf->SetX($x_axis_initial+100);
        $pdf->MultiCell(98, 4, '1m', 0, 'L', 0, 0, '', '', true);
        
        $pdf->SetY($y_axis0);
        $pdf->SetX($x_axis_initial+115);
        $pdf->MultiCell(20, 4, '= ', 0, 'C', 0, 0, '', '', true);
        
        $pdf->SetY($y_axis0);
        $pdf->SetX($x_axis_initial+135); 
        $pdf->MultiCell(48, 4, '3.280839895', 0, 'R', 0, 0, '', '', true);
        
        $pdf->SetY($y_axis0);
        $pdf->SetX($x_axis_initial+183); 
        $pdf->MultiCell(15, 4, 'ft', 0, 'L', 0, 0, '', '', true);
        
        $y_axis0=$y_axis0+4;
        $pdf->SetY($y_axis0);
        $pdf->SetX($x_axis_initial+100);
        $pdf->MultiCell(98, 4, '1m3', 0, 'L', 0, 0, '', '', true);
        
        $pdf->SetY($y_axis0);
        $pdf->SetX($x_axis_initial+115);
        $pdf->MultiCell(20, 4, '= ', 0, 'C', 0, 0, '', '', true);
        
        $pdf->SetY($y_axis0);
        $pdf->SetX($x_axis_initial+135); 
        $pdf->MultiCell(48, 4, '35.31466672', 0, 'R', 0, 0, '', '', true);
        
        $pdf->SetY($y_axis0);
        $pdf->SetX($x_axis_initial+183); 
        $pdf->MultiCell(15, 4, 'ft3 (scf)', 0, 'L', 0, 0, '', '', true);
        
        $y_axis0=$y_axis0+4;
        $pdf->SetY($y_axis0);
        $pdf->SetX($x_axis_initial+100);
        $pdf->MultiCell(98, 4, '1MM', 0, 'L', 0, 0, '', '', true);
        
        $pdf->SetY($y_axis0);
        $pdf->SetX($x_axis_initial+115);
        $pdf->MultiCell(20, 4, '= ', 0, 'C', 0, 0, '', '', true);
        
        $pdf->SetY($y_axis0);
        $pdf->SetX($x_axis_initial+135); 
        $pdf->MultiCell(48, 4, '1,000,000', 0, 'R', 0, 0, '', '', true);
        
        $pdf->SetY($y_axis0);
        $pdf->SetX($x_axis_initial+183); 
        $pdf->MultiCell(15, 4, ' ', 0, 'L', 0, 0, '', '', true);
        
        $y_axis0=$y_axis0+4;
        $pdf->SetY($y_axis0);
        $pdf->SetX($x_axis_initial+100);
        $pdf->MultiCell(98, 4, '', 0, 'L', 0, 0, '', '', true);
        
        $pdf->SetFont('helvetica', 'B', 6);  	
        
        $y_axis0=$y_axis0+4;
        $pdf->SetY($y_axis0);
        $pdf->SetX($x_axis_initial+100);
        $pdf->MultiCell(98, 4, '1MMBTU', 0, 'L', 0, 0, '', '', true);
        
        $pdf->SetY($y_axis0);
        $pdf->SetX($x_axis_initial+115);
        $pdf->MultiCell(20, 4, '= ', 0, 'C', 0, 0, '', '', true);
        
        $pdf->SetY($y_axis0);
        $pdf->SetX($x_axis_initial+135); 
        
        
        $x     = $avg * 35.31466672;
        $mmbtu = 1000000/$x;
        $pdf->MultiCell(48, 4, number_format($mmbtu,"4",".",","), 0, 'R', 0, 0, '', '', true);
        
        $pdf->SetY($y_axis0); $pdf->SetX($x_axis_initial+183); 
        $pdf->MultiCell(15, 4, 'Sm3', 0, 'L', 0, 0, '', '', true);
        
        $y_axis=$pdf->getY();
        $y_axis=$y_axis+8;
        
        $pdf->SetFont('helvetica', 'B', 7);
        
        $pdf->SetY($y_axis);
        $pdf->SetX($x_axis_initial); 	
        
        $pdf->SetFont('helvetica', '', 6);

        $pdf->Line($x_axis_initial, $y_axis+5, 205, $y_axis+5);
        $pdf->SetFont('helvetica', 'B', 7);
        
        $y_axis=$y_axis+3;
        $pdf->SetY($y_axis);
        $pdf->SetX($x_axis_initial); 	
        $pdf->Text($x_axis_initial, $y_axis+3, 'GAS CONSUMPTION');  
        
        $y_axis=$y_axis+10; $y_axis0=$y_axis;
        $pdf->SetY($y_axis);
        $pdf->SetX($x_axis_initial); 	
        $pdf->Cell(98, 4, 'Volume Data (Sm'.$pdf->unichr(179).')', 1, 1, 'C', 1, '', 0, false, 'T', 'C'); 
        
        $y_axis=$y_axis+4;
        $pdf->SetY($y_axis);
        $pdf->SetX($x_axis_initial); 	
        $pdf->MultiCell(38, 8, 'Period', 1, 'C', 0, 0, '', '', true, 0, false, true, 8, 'M');
        $pdf->MultiCell(20, 8, 'Last Month', 1, 'C', 0, 0, '', '', true, 0, false, true, 8, 'M');
        $pdf->MultiCell(20, 8, 'This Month', 1, 'C', 0, 0, '', '', true, 0, false, true, 8, 'M');
        $pdf->MultiCell(20, 8, 'Vol. Used', 1, 'C', 0, 0, '', '', true, 0, false, true, 8, 'M');
        $y_axis=$y_axis+8;  
        
        $use = 0;
        $tot_metering = COUNT($metering); 
        foreach($metering as $row_metering):
            $pdf->SetY($y_axis);
            $pdf->SetX($x_axis_initial);
            $row_height=4;
            $pdf->MultiCell(38, $row_height, $row_metering['ItemLine'], 1, 'C', 0, 0, '', '', true);
        	$pdf->MultiCell(20, $row_height, number_format($row_metering['Meteran_Awal'],0,".",","), 1, 'R', 0, 0, '', '', true);
        	$pdf->MultiCell(20, $row_height, number_format($row_metering['Meteran_Akhir'],0,".",","), 1, 'R', 0, 0, '', '', true);
        	$pdf->MultiCell(20, $row_height, number_format($row_metering['Pemakaian'],0,".",","), 1, 'R', 0, 0, '', '', true);
        	$y_axis=$y_axis+$row_height;
            $use = $use + $row_metering['Pemakaian'];
        endforeach;
        
        if($tot_metering < 5):
        	for($m=$tot_metering;$m<5;$m++):
        		$pdf->SetY($y_axis); $pdf->SetX($x_axis_initial); 	
        		$pdf->MultiCell(38, 4, ' ', 1, 'C', 0, 0, '', '', true);
        		$pdf->MultiCell(20, 4, ' ', 1, 'C', 0, 0, '', '', true);
        		$pdf->MultiCell(20, 4, ' ', 1, 'C', 0, 0, '', '', true);
        		$pdf->MultiCell(20, 4, ' ', 1, 'C', 0, 0, '', '', true);
        		$y_axis=$y_axis+4;
        	endfor;
        endif;
        $pdf->SetY($y_axis);
        $pdf->SetX($x_axis_initial); 	
        $pdf->MultiCell(78, 4, ' Total ', 1, 'C', 0, 0, '', '', true);
        $pdf->MultiCell(20, 4, number_format($use,0,".",","), 1, 'R', 0, 0, '', '', true);
        $y_axis=$y_axis+4; 
        
        $pdf->SetY($y_axis0);
        $pdf->SetX($x_axis_initial+100);  
        $pdf->Cell(98, 4, 'Monthly Gas Used', 1, 1, 'C', 1, '', 0, false, 'T', 'C');
        $tot_line = COUNT($line);
            if($tot_line!=0):
                $width=65/$tot_line;
                $y_axis0=$y_axis0+4;
            	$pdf->SetY($y_axis0);
                $pdf->SetX($x_axis_initial+100);
                $pdf->Cell(13, 8, '', 1, 1, 'C', 1, '', 0, false, 'T', 'C');
	            $x_axis2=$x_axis_initial+113;  
                foreach($line as $mmbtu): 
            		$pdf->SetY($y_axis0); 
                    $pdf->SetX($x_axis2);	
            		$x_axis2=$x_axis2+$width;
            		$tot_word=strlen($mmbtu['Keterangan']);
            		if($tot_word>=20)
            			$pdf->MultiCell($width,8,$mmbtu['Keterangan'], 1, 'C', 0, 0, '', '', true);
            		else
            			$pdf->Cell($width, 8,$mmbtu['Keterangan'], 1, 1, 'C', 1, '', 0, false, 'T', 'C');
                endforeach;  
                
                $pdf->SetY($y_axis0);
                $pdf->SetX($x_axis2);
	            $pdf->Cell(20, 8, 'Total Quantity ', 1, 1, 'C', 1, '', 0, false, 'T', 'C');
	            
                $y_axis0=$y_axis0+8;
            	$pdf->SetY($y_axis0); $pdf->SetX($x_axis_initial+100);
            	$pdf->Cell(13, 12, 'MMBTU', 1, 1, 'C', 1, '', 0, false, 'T', 'C');  
                
                $x_axis2=$x_axis_initial+113;
                $mmbtux = 0;
                foreach($line as $mmbtu): 
                    $pdf->SetY($y_axis0);
                    $pdf->SetX($x_axis2);
            		$pdf->Cell($width, 12, number_format($mmbtu['pemakaian_mmbtu'],2,".",","), 1, 1, 'R', 1, '', 0, false, 'T', 'C');
            		$x_axis2=$x_axis2+$width;
                    $mmbtux = $mmbtux + $mmbtu['pemakaian_mmbtu'];
                endforeach;
                $pdf->SetY($y_axis0);
                $pdf->SetX($x_axis2);
	            $pdf->Cell(20, 12, number_format($mmbtux,2,".",","), 1, 1, 'R', 1, '', 0, false, 'T', 'C');
                
                $y_axis0=$y_axis0+12;
	            $pdf->SetY($y_axis0);
                $pdf->SetX($x_axis_initial+100); 
                
                $pdf->Cell(13, 12, 'Sm3', 1, 1, 'C', 1, '', 0, false, 'T', 'C');
                
                $x_axis2=$x_axis_initial+113;
                $mmbtuxx = 0;
                foreach($line2 as $mmbtu2):
                    $pdf->SetY($y_axis0); $pdf->SetX($x_axis2);
            		$pdf->Cell($width, 12, number_format($mmbtu2['pemakaian_m3'],2,".",","), 1, 1, 'R', 1, '', 0, false, 'T', 'C');
            		$x_axis2=$x_axis2+$width;
                    $mmbtuxx = $mmbtuxx + $mmbtu2['pemakaian_m3'];
                endforeach;
                $pdf->SetY($y_axis0); $pdf->SetX($x_axis2);
	            $pdf->Cell(20, 12, number_format($mmbtuxx,2,".",","), 1, 1, 'R', 1, '', 0, false, 'T', 'C');
            endif;
            
        $y_axis0=$pdf->getY();
        $y_axis0=$y_axis0+12;
        $pdf->SetY($y_axis0);
            
        $pdf->SetX($x_axis_initial+150);
        $pdf->MultiCell(50, 4, 'Jakarta '.days_in_month($month,$year).' '.month_name($month).' '.$year, 0, 'C', 0, 0, '', '', true);
        $y_axis0=$y_axis0+4;
            
        $pdf->SetY($y_axis0);
        $pdf->SetX($x_axis_initial+150);
        $pdf->MultiCell(50, 4, 'PT. Bayu Buana Gemilang', 0, 'C', 0, 0, '', '', true);
             
        $y_axis0=$y_axis0+6;
        $pdf->SetY($y_axis0);
        $pdf->SetX($x_axis_initial);
        $pdf->Cell(50, 4, 'Prepared By', 1, 1, 'C', 1, '', 0, false, 'T', 'C');
            
        $x_axis=$x_axis_initial+50;
        $pdf->SetY($y_axis0);
        $pdf->SetX($x_axis); 	
        $pdf->Cell(50, 4, 'Checked By', 1, 1, 'C', 1, '', 0, false, 'T', 'C');
            
        $x_axis=$x_axis+50;
        $pdf->SetY($y_axis0);
        $pdf->SetX($x_axis); 	
        $pdf->Cell(50, 4, 'Aproved By', 1, 1, 'C', 1, '', 0, false, 'T', 'C');
        
        $y_axis0=$y_axis0+4;
        $pdf->SetY($y_axis0); $pdf->SetX($x_axis_initial);
        
        $pdf->MultiCell(50, 22, ' ', 1, 'C', 0, 0, '', '', true);
        $pdf->MultiCell(50, 22, ' ', 1, 'C', 0, 0, '', '', true);
        $pdf->MultiCell(50, 22, ' ', 1, 'C', 0, 0, '', '', true);
        
        $y_axis0=$y_axis0+22;
        $pdf->SetY($y_axis0);
        $pdf->SetX($x_axis_initial);
        $pdf->MultiCell(50, 4, 'APIP SUPRIYATNA', 1, 'C', 0, 0, '', '', true, 0, false, true, 4, 'M');
        $pdf->MultiCell(50, 4, 'CIPTADI HERU WIDODO', 1, 'C', 0, 0, '', '', true, 0, false, true, 4, 'M');
        $pdf->MultiCell(50, 4, 'MONO ARINTA P', 1, 'C', 0, 0, '', '', true, 0, false, true, 4, 'M');
        
        $y_axis0=$y_axis0+4;
        $pdf->SetY($y_axis0);
        $pdf->SetX($x_axis_initial);
        $pdf->MultiCell(50, 4, 'Database Administrator', 1, 'C', 0, 0, '', '', true, 0, false, true, 4, 'M');
        $pdf->MultiCell(50, 4, 'Operation & Maintenance Manager', 1, 'C', 0, 0, '', '', true, 0, false, true, 4, 'M');
        $pdf->MultiCell(50, 4, 'Operation Director', 1, 'C', 0, 0, '', '', true, 0, false, true, 4, 'M'); 
                                                                                              
        return $pdf->Output("Gas-Consumption.pdf","I");
   } 
   
   function getPdfVolume($month,$year){
        /** Session Variabel **/
        $month =   $this->session->userdata('vol_month');
        $year  =   $this->session->userdata('vol_year');
        
        $custGroup = $this->customers->getAllCustomer('group'); /** Customer **/
        $daily = $this->gas->getDailyEvc($month,$year,'','distinct'); /** gas volume **/
        
        $pdf = tcpdf();
        $pdf->setPageOrientation ('L', '', 8);
        $pdf->setPrintHeader(false);
        $pdf->setPrintFooter(false);
        $k=0;
        $pdf->AddPage();
        
        /** initialization of x & y axis **/
        $x_axis_initial = 7;
        $y_axis_initial = 7;
        $x_axis = $x_axis_initial;
        $y_axis = $y_axis_initial; 
        
        $pdf->SetFont('helvetica', 'B', 9);
        $pdf->SetFillColor(255, 255, 255);
        $pdf->SetTextColor(0, 0, 0);
        $pdf->SetDrawColor(0, 0, 0);
        $pdf->SetLineWidth(0.3); 
        
        $y_axis0=$y_axis+7; 
        $y_axis=$y_axis;
        
        $pdf->SetY($y_axis0);
        $pdf->SetX($x_axis_initial); 	
        $pdf->SetY($y_axis);
        $pdf->SetX($x_axis_initial+4);
        $judul="TABEL PEMAKAIAN VOLUME GAS KONSUMEN PT. BBG ";
        
        $i=1;
        $tot_cust = 0;
        foreach($custGroup  as $row_area):
            $area[$i] = $row_area['CustomerGroup'];
            $total[$i]= COUNT($this->customers->getAllCustomer('',$row_area['CustomerGroup'])); 
            $tot_cust = $tot_cust + $total[$i];
            $i++;
            endforeach;
        $n_customer = $tot_cust + $i;
        $width=270/$n_customer;
        
        for($k=1;$k<$i;$k++):
            if($k<$i):
            	$judul = $judul.$area[$k];
                $j = $k; 
            	if($j < $i):
            		$judul = $judul." & ";
            	endif;
            endif;    
        endfor;
        $pdf->Cell(270, 7, $judul, 0, 0, 'C', 1);
        
        $y_axis=$y_axis+7; 
        $pdf->SetY($y_axis);
        $pdf->SetX($x_axis_initial+4);
        $pdf->Cell(270, 7, 'Periode '.month_name($month).' '.$year, 0, 0, 'C', 1); 
        
        $pdf->SetFillColor(205, 201, 201);
        $pdf->SetFont('helvetica', 'B', 7); 
        
        $y_axis=$y_axis+8;
        $pdf->SetY($y_axis);
        $pdf->SetX($x_axis_initial); 	
        $pdf->Cell(7, 16,'No', 1, 1, 'C', 1, '', 0, false, 'T', 'C');
        
        $x_axis=$x_axis+7;
        $pdf->SetY($y_axis);
        $pdf->SetX($x_axis); 	
        $pdf->Cell(8,16,'Tgl', 1, 1, 'C', 1, '', 0, false, 'T', 'C');
        
        $x_axis=$x_axis+8;
        $pdf->SetY($y_axis);
        $pdf->SetX($x_axis); 	
        $pdf->Cell(269,4,'Customer', 1, 1, 'C', 1, '', 0, false, 'T', 'C');
        
        $y_axis=$y_axis+4; $x_axis=$x_axis_initial+15; 
        
        for($n=1;$n<=$i;$n++):
            if($i>$n):
             	$pdf->SetY($y_axis);
                $pdf->SetX($x_axis); 	
            	$width2=($total[$n] * $width) + $width;
            	$pdf->Cell($width2, 4, $area[$n], 1, 1, 'C', 1, '', 0, false, 'T', 'C');
            	$x_axis=$x_axis+$width2;
            endif;    	
        endfor;
        
        $pdf->SetY($y_axis);
        $pdf->SetX($x_axis); 		
		$pdf->Cell(13, 8, 'TOTAL', 1, 1, 'C', 1, '', 0, false, 'T', 'C');
        
        $y_axis=$y_axis+4;
        $x_axis=$x_axis_initial+15;
        $total=0;
        for($n=1;$n<$i;$n++){ 
            $Q=$this->customers->getAllCustomer('',$area[$n]);
            foreach($Q as $row_cust):
                $pdf->SetY($y_axis);
                $pdf->SetX($x_axis); 		
        		$pdf->Cell($width, 4, $row_cust['KodePerusahaan'], 1, 1, 'C', 1, '', 0, false, 'T', 'C');
        		$pdf->SetY($y_axis+4);
                $pdf->SetX($x_axis); 		
        		$pdf->Cell($width, 4, 'Sm3', 1, 1, 'C', 1, '', 0, false, 'T', 'C');
        		$x_axis=$x_axis+$width;	
            endforeach;
            $pdf->SetY($y_axis); $pdf->SetX($x_axis); 		
    		$pdf->Cell($width, 4, 'Sub Total', 1, 1, 'C', 1, '', 0, false, 'T', 'C'); 
    		$pdf->SetY($y_axis+4); $pdf->SetX($x_axis); 		
    		$pdf->Cell($width, 4, 'MMSCFD', 1, 1, 'C', 1, '', 0, false, 'T', 'C');
    		$x_axis=$x_axis+$width;	
        }    
        $pdf->SetY($y_axis+4);
        $pdf->SetX($x_axis); 		
	    $pdf->Cell(13, 4, 'MMSCFD', 1, 1, 'C', 1, '', 0, false, 'T', 'C');
        
        $y_axis=$y_axis+4;
        $pdf->SetFillColor(255, 255, 255);
        
        $sub_total_all=0;
        $total_all=0;		
        $no=1;
        $total_data = count($daily);

        $pdf->SetFont('helvetica', '', 7);
        foreach($daily as $row):
            if($row['day_name']=="Sunday"):
    		   $pdf->SetFillColor(255,0,0);
    	    elseif($row['day_name']=="Saturday"):
    		   $pdf->SetFillColor(0, 255, 255);
    	    else:
    		   $pdf->SetFillColor(255, 255, 255);
    	    endif;
            $y_axis=$y_axis+4;
            $x_axis=$x_axis_initial;
            $pdf->SetY($y_axis);
            $pdf->SetX($x_axis); 		
        	$pdf->Cell(7, 4, $no, 1, 1, 'C', 1, '', 0, false, 'T', 'C');
            
       		$x_axis=$x_axis+7;
            $pdf->SetY($y_axis);
            $pdf->SetX($x_axis); 		
        	$pdf->Cell(8, 4,substr($row['Date'],8,2) , 1, 1, 'C', 1, '', 0, false, 'T', 'C');
            $no++;
            
            $x_axis=$x_axis+8;
            $total=0;
            for($n=1; $n<$i; $n++):
                $custData  = $this->customers->getAllCustomer('',$area[$n]);
                $sub_total_all=0;
                $sub_total_flow=0;
                $x=0;
                $sub_total=0;
                foreach($custData as $row_cust2):
                    $row_daily = $this->getDailyEvc($month,$year,$row_cust2['CustID'],'',$row['Date']);
                    if(COUNT($row_daily))
                        $flow_rate = number_format($row_daily['FlowRate'],3,'.',',');
                    else
                        $flow_rate = '0.000';
                    $sub_total_flow = $sub_total_flow + $flow_rate;
                    $pdf->SetY($y_axis);
                    $pdf->SetX($x_axis); 		
        			$pdf->Cell($width, 4, $flow_rate, 1, 1, 'R', 1, '', 0, false, 'T', 'C');
        			$x_axis=$x_axis+$width; 
                endforeach;
                
                $x=$sub_total_flow * 35.3147;
        		$sub_total=($x / 1000000);
        		$sub_total_all=$sub_total_all+$sub_total;
        		$s_total_all[$n]= $sub_total_all;
        		$total = $total + $sub_total;
        		$total_all = $total_all+$total;
        		$sub_totalx=number_format($sub_total,2,'.',',');
        		
       			$pdf->SetY($y_axis);
                $pdf->SetX($x_axis); 		
        		$pdf->Cell($width, 4, $sub_totalx, 1, 1, 'R', 1, '', 0, false, 'T', 'C');
        		$x_axis=$x_axis+$width;
            endfor;
            $total=number_format($total,2,'.',',');
    		$pdf->SetY($y_axis);
            $pdf->SetX($x_axis); 		
    	    $pdf->Cell(13, 4, $total, 1, 1, 'R', 1, '', 0, false, 'T', 'C'); 
	    $no++;	
        endforeach;
        
        $pdf->SetFont('helvetica', 'B', 7); 
        $pdf->SetFillColor(205, 201, 201);
        $y_axis=$y_axis+4;
        $x_axis=$x_axis_initial;
        $pdf->SetY($y_axis);
        $pdf->SetX($x_axis); 
        $pdf->Cell(15, 4, 'Average', 1, 1, 'C', 1, '', 0, false, 'T', 'C');
        
    	$x_axis=$x_axis+15; 		
        $avg_total=0;
        
        for($n=1;$n<$i; $n++):
            $Q=$this->customers->getAllCustomer('',$area[$n]);
            $avg_sub_total=0;
            $sub_total_flow=0;
            //$x=0;
            $sub_total=0;
            foreach($Q as $rowCust2):
                $average = $this->gas->AverageGas('FlowRate',$month,$year,$rowCust2['CustID']);
                $avg = decimal($average['FlowRate'],3);
                if($avg)
                    $avg = $avg;
                else
                    $avg = '0.000';
                    
                $pdf->SetY($y_axis);
                $pdf->SetX($x_axis); 
        		$pdf->Cell($width, 4, $avg, 1, 1, 'R', 1, '', 0, false, 'T', 'C');
        		$x_axis=$x_axis+$width;  
            endforeach;
            $avg_sub_total=$s_total_all[$n]/$total_data;                             
        	$avg_sub_total = number_format($avg_sub_total,3,'.',',');
        	$pdf->SetY($y_axis);
            $pdf->SetX($x_axis); 
        	$pdf->Cell($width, 4, $avg_sub_total, 1, 1, 'R', 1, '', 0, false, 'T', 'C');
        	$x_axis=$x_axis+$width;  
	        $avg_total=$avg_total+$avg_sub_total;
        endfor;
        $avg_total=number_format($avg_total,3,'.',',');
        $pdf->SetY($y_axis);
        $pdf->SetX($x_axis); 
       	$pdf->Cell(13, 4, $avg_total, 1, 1, 'R', 1, '', 0, false, 'T', 'C');
        
        $y_axis=$y_axis+4;
        $x_axis=$x_axis_initial; $pdf->SetY($y_axis); $pdf->SetX($x_axis); 	
 
        $pdf->Cell(15, 8, 'TOTAL', 1, 1, 'C', 1, '', 0, false, 'T', 'C');
	    $x_axis=$x_axis+15; 
        
        for($n=1;$n<$i; $n++):
            $sub_total_flow=0;
            $x=0;
            $sub_total=0;
            $Q=$this->customers->getAllCustomer('',$area[$n]);
            foreach($Q as $rowCust):
                $evc = $this->gas->getSUMDailyEvc('FlowRate',$month,$year,$rowCust['CustID']);
                if(COUNT($evc))
                    $total_flow = number_format($evc['FlowRate'],3,'.',',');
                else
                    $total_flow = '0.000';
                
                $pdf->SetY($y_axis);
                $pdf->SetX($x_axis); 	
 		        $pdf->Cell($width, 4, $total_flow, 1, 1, 'R', 1, '', 0, false, 'T', 'C');
                $x_axis=$x_axis+$width;     
            endforeach;
            $pdf->SetY($y_axis);
            $pdf->SetX($x_axis); 	
	        $pdf->Cell($width, 4, number_format($s_total_all[$n],2,'.',','), 1, 1, 'R', 1, '', 0, false, 'T', 'C');
		    $x_axis=$x_axis+$width; 
        endfor;
        if($total_all!=0){
	       $avg_total=$total_all/$total_data;							
        }else{
        	$avg_total=0;							
        }
        $pdf->SetY($y_axis);
        $pdf->SetX($x_axis); 	
	    $pdf->Cell(13, 4, number_format($total_all,2,'.',','), 1, 1, 'R', 1, '', 0, false, 'T', 'C');
        
        $y_axis=$y_axis+4;
        $x_axis=$x_axis_initial+15;
        
        for($n=1;$n<$i;$n++):
            $Q=$this->customers->getAllCustomer('',$area[$n]);
            foreach($Q as $cust):
                $pdf->SetY($y_axis);
                $pdf->SetX($x_axis); 	
        		$pdf->Cell($width, 4,$cust['KodePerusahaan'], 1, 1, 'C', 1, '', 0, false, 'T', 'C');
        		$x_axis=$x_axis+$width; 
            endforeach;
                $pdf->SetY($y_axis);
                $pdf->SetX($x_axis); 	
            	$pdf->Cell($width, 4, '', 1, 1, 'C', 1, '', 0, false, 'T', 'C');
            	$x_axis=$x_axis+$width; 	
        endfor;
        $pdf->SetY($y_axis);
        $pdf->SetX($x_axis); 	
        $pdf->Cell(13, 4, '', 1, 1, 'C', 1, '', 0, false, 'T', 'C');
                
        return $pdf->Output("Gas-Area.pdf","I");
   }         
    
}    